package edu.umassd.visual.components;

import java.awt.Color;
import java.text.DecimalFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import processing.core.PFont;
import edu.umassd.visual.Display;
import edu.umassd.visual.View;
import edu.umassd.visual.options.SelectFont;

@Component("screensize")
public class ScreenSize implements Displayable<Display>
{
	@Autowired
	private View view;

	@Autowired
	private SelectFont selectedFont;

	private static final DecimalFormat FORMAT = new DecimalFormat("0.00");

	private boolean visible = true;

	@Override
	public void display(Display display)
	{
		if (visible)
		{
			PFont font = selectedFont.getBigFont();

			int w = display.width;
			int h = display.height;

			String viewW = FORMAT.format(view.getWidth());
			String viewH = FORMAT.format(view.getHeight());

			display.fill(Color.WHITE);
			display.textFont(font);
			display.textAlign(Display.CENTER, Display.TOP);
			display.text("{ " + viewW + " }", w / 2, 10);

			display.textAlign(Display.RIGHT, Display.CENTER);
			display.text("{ " + viewH + " }", w - 10, h / 2);
		}
	}

	public void setVisible(boolean visible)
	{
		this.visible = visible;
	}
}
